var mobile="";



$(document).ready(function () {
$.jgrid.defaults.styleUI = "Bootstrap";
$("#table_list_1").jqGrid({
    data: [],
    datatype: "local",
    height: "100%",
    autowidth: true,
    shrinkToFit: true,
    rowNum: 10,
    rowList: [10, 20, 30,60,90,100,200,500],
    //colNames: ["编号", "名称", "手机号码"],
    colModel: [{
        name:'devicenumber', index: 'devicenumber',align:"center", width: 25, label: "设备号", align: 'center',

    }, 
    {
        name: 'devicename', index: 'devicename', align: "center", width: 25, label: "名称", align: 'center',

    },  
    {
        name: 'isonline', index: 'isonline', align: "center", width: 20, label: "状态", align: 'center',
        formatter: function (value, options, row) {
            if (value == "1") {
                value = "<img src=static/img/zx.png class=img-rounded style='height:27px;width:30px;'>";

            } else {
                value = "<img src=static/img/lx.png class=img-rounded style='height:27px;width:30px;'>";


            }
            return value;

        }

    },
    
    {
        name:'send_speed', index: 'send_speed',align:"center", width: 40, label: "进度(%)", align: 'center',
        formatter: function (value, options, row) {

             return "<div class='progress progress-mini progress-striped' style='margin:0px 10px;'><div style='width:"+value+"%;color:black;' class='progress-bar progress-bar-success'>"+value+"%</div></div>";
        }
    },
 
],
    pager: "#pager_list_1",
    viewrecords: true,
    multiselect:true,
    caption: "设备列表",
    hidegrid: false,
    ondblClickRow:function(row){
    $("#update").click();
    modify(row);
      // $('#myModal').modal('show')
    },
    onPaging:function(pageBtn){
        console.log(":"+pageBtn);
//	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数
        var re_page =  $("#table_list_1").getGridParam('page');//获取返回的当前页
        var re_rowNum=  $("#table_list_1").getGridParam('rowNum');//获取每页数
        var re_total=  $("#table_list_1").getGridParam('lastpage');//获取总页数
        //alert(re_total);
        
        if(pageBtn==="next"){
           // initJqgrid(re_page+1,re_rowNum);
          // if()
           pageval=pageval+1;
           cxlist();
        }
        if(pageBtn==="prev"){
            
            pageval=pageval-1;  cxlist();
        }

        if(pageBtn=="last"){
  
            pageval=re_total;
          
            cxlist();

        }
        if(pageBtn=="first"){
  
            pageval=1;
          
            cxlist();

        }
        
        if(pageBtn=="records"){

            sizeval=$(".ui-pg-selbox").val();
            pageval=1;
            cxlist();
        }
    },

});
$("#table_list_1").setGridHeight($(window).height() * 0.73);

 $(window).resize(function(){
    $("#table_list_1").setGridWidth($(window).width());  
    $("#table_list_1").setGridHeight($(window).height() * 0.73);
});
});
var sizeval=20;
var pageval=1;
var usernameval=$("#usnameval").val();
var conameval="";
var json="";



window.cxlist=function(){
  
    // domain.ajaxUrl({
    //     method: 'POST',
    //    // url: domain.testUrl+"/Threeinjection/DeviceManagement/queryProgramInfoAndDeviceInfo",
    //     data: {size:sizeval,page:pageval,companyId:sessionStorage.getItem("coid"),sessionid:sessionStorage.getItem("sid"),
    //              "programId":sessionStorage.getItem("programid")},         
    //      // datatype:"JSON",
    //     success: function (response) {
        
    //         json=response;
    //         var data=JSON.parse(response);
    //         var reader = {
    //             root: function (obj) { return data.rows; },
    //             page: function (obj) { return pageval; },
    //             total: function (obj) { return data.taotal; },
    //             records: function (obj) {

    //                 return data.records;
    //             },
               
    //         };
         
    
    //    $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
    //         var re_records = $("#table_list_1").getGridParam('records');
          
    //         if(re_records==0||re_records==null){
    //             if($(".norecords").html() == null){
    //                 $("#table_list_1").parent().append("<div class=\"norecords\">没有符合数据</div>");
    //             }
    //             $(".norecords").show();
    //         }else{

    //             $(".norecords").hide();
    //         }

         
           
    //         console.log("在这"+response);
          
    //     }
    // });
}
 





 Date.prototype.Format = function(fmt)   
{ 
//author:wangweizhen
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日
    "h+" : this.getHours(),                   //小时   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}


$(function(){
    $("#gview_table_list_1").css("height","500px");
  cxlist();
  $("#sxDevice").click(function(){
    // sizeval = 10;
    // pageval = 1;
  
    cxlist();
});
   
});




